package edu.hawaii.duedates.user;

import java.util.ArrayList;
import java.util.List;
import edu.hawaii.duedates.configuration.jaxb.Library;

/**
 * The User Class implements the IUser interface. A user is comprised of a email,
 * password, and validity of the user.
 * 
 * @author Ronn Reeves and Robin E. Raqueno
 */
public class User implements IUser {
  /** Unique identifier for this instance. */
  private static final long serialVersionUID = 1L;

  /** The user's password. */
  private String password;

  /** The user's email. */
  private String email;

  /** The user's validity. */
  private boolean validity;
  
  /** The user's name. */
  private String name;
  
  /** The library list. */
  private List<Library> library;

  /**
   * Creates a user object with the given user id, password, and a default validity of false.
   * 
   * @param name The user's name.
   * @param email The user's id.
   * @param password The user's password.
   */
  public User(String name, String email, String password) {
    this.name = name;
    this.email = email;
    this.password = password;
    this.validity = false;
  }
  
  /**
   *  This returns a List of library based on the user.
   *  
   * @return List Library.
   */
   
   public List<Library> getLibrary() {
     if (library == null) {
         library = new ArrayList<Library>();
     }
     return this.library;
   }
  /**
   * Returns the user's name.
   * 
   * @return String The user's name.
   */
  
  public String getName() {
    return name;
  }
  /**
   * Returns this user's password.
   * 
   * @return String The user's password.
   */
  public String getPassword() {
    return this.password;
  }
  
  /**
   * Sets the user's name.
   * 
   * @param name which contains the new name.
   */
  
  public void setName(String name) {
    this.name = name;
  }  

  /**
   * Returns this user's Email.
   * 
   * @return String The user Email.
   */
  public String getEmail() {
    return this.email;
  }

  /**
   * Returns true if the user is valid.
   * 
   * @return Boolean The validity of the user.
   */
  public boolean isValid() {
    return this.validity;
  }

  /**
   * Sets this user's password.
   * 
   * @param password The user's password.
   */
  public void setPassword(String password) {
    this.password = password;
  }

  /**
   * Sets this user's Email.
   * 
   * @param email The user's Email.
   */
  public void setEmail(String email) {
    this.email = email;
  }

  /**
   * Sets the validity of this user.
   * 
   * @param validity The validity status of this user.
   */
  public void setValid(boolean validity) {
    this.validity = validity;

  }

  /**
   * Returns the user id.
   * 
   * @return String The user id.
   */
  public String toString() {
    return this.getEmail();
  }
}
